package com.henu.main.util;

import com.henu.main.entities.Metric;

import java.util.HashMap;

public class PushExecutor implements Runnable {

    @Override
    public void run() {
        while (true) {
            if (MetricsUtil.queue.size() > 0) {
                System.out.println(MetricsUtil.queue.size());
                Object metric = null;
                try {
                    metric = MetricsUtil.queue.take();
                    if (metric instanceof Metric) {
                        PushGateWayUtil.push((Metric) metric);
                    } else if (metric instanceof HashMap) {
                        PushGateWayUtil.push((HashMap) metric);
                    } else {
                        System.out.println("没有该类型" + metric.getClass());
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                Thread.yield();
            }
        }
    }
}
